import sympy

if __name__ == '__main__':
    for i in range(1001, 10000 - 6660, 2):
        if sympy.isprime(i) and sympy.isprime(i + 3330) and sympy.isprime(i + 6660):
            s1 = ''.join(sorted([j for j in str(i)]))
            s2 = ''.join(sorted([j for j in str(i + 3330)]))
            s3 = ''.join(sorted([j for j in str(i + 6660)]))
            if s1 == s2 == s3:
                print(i, i + 3330, i + 6660, sep='')
